package com.xl.studentpass.controller;

import com.xl.studentpass.entity.vo.CommentVo;
import com.xl.studentpass.service.CommentService;
import com.xl.studentpass.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: xl
 * @createTime: 2023/6/7 11:25:58
 * @program: student-pass
 * @e-mail: 2199396150@qq.com
 * @description:
 */
@RestController
@Slf4j
@Api(tags = "评论相关接口")
@RequestMapping("/comment")
public class CommentController {

    @Resource
    CommentService commentService;

    /**
     * 发布评论
     */
    @PostMapping("/posting")
    @ApiOperation("发布评论")
    public R createComment(@RequestBody CommentVo commentVO) {

        log.info(this.getClass().getSimpleName() + "========评论相关接口");
        Integer comment = commentService.createComment(commentVO);
        if (ObjectUtils.isEmpty(comment) || comment <= 0) {
            return R.error();
        }
        return R.ok();
    }

    /**
     * 删除评论
     */
    @PostMapping("/delete")
    @ApiOperation("删除评论")
    public R deleteComment(@RequestParam("commentId") @ApiParam("需要删除的评论id") Integer commentId) {
        log.info(this.getClass().getSimpleName() + "===========删除评论");
        Integer integer = commentService.deleteComment(commentId);
        if (ObjectUtils.isEmpty(integer) || integer <= 0) {
            return R.error();
        }
        return R.ok();
    }
}
